package com.xjgc.common.utils;


import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.converts.PostgreSqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MPGenerator {

    public static void main(String[] args) {
        AutoGenerator autoGenerator = new AutoGenerator();
        GlobalConfig globalConfig = new GlobalConfig();


        globalConfig.setOutputDir("D:\\workspace-zhhl\\bjxj-imis\\bjxj-imis-moudle-msiwebserver\\src\\main\\java");
        globalConfig.setFileOverride(false);
        globalConfig.setActiveRecord(true);
        globalConfig.setEnableCache(false);
        globalConfig.setBaseResultMap(true);
        globalConfig.setBaseColumnList(false);
        globalConfig.setAuthor("htx");
        autoGenerator.setGlobalConfig(globalConfig);

        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.POSTGRE_SQL);
        dataSourceConfig.setTypeConvert(new PostgreSqlTypeConvert());
        dataSourceConfig.setUrl("jdbc:postgresql://20.142.3.29:19201/postgres?useUnicode=true&useSSL=false&characterEncoding=utf8");
        dataSourceConfig.setDriverName("org.postgresql.Driver");
        dataSourceConfig.setUsername("postgres");
        dataSourceConfig.setPassword("postgres");
        autoGenerator.setDataSource(dataSourceConfig);

        StrategyConfig strategyConfig = new StrategyConfig();
//        strategyConfig.setTablePrefix(new String[]{"zxj_eip_"}); //加完之后生成的类名没有前缀
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setInclude(new String[]{"zxj_eip_order"});//需要生成的表名
        autoGenerator.setStrategy(strategyConfig);

        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent("com.xjgc.ws.eip");
        packageConfig.setMapper("dao");
        packageConfig.setXml("mapperxml");
        packageConfig.setEntity("entity");
        packageConfig.setService("service");
        packageConfig.setServiceImpl("service.serviceImpl");
        autoGenerator.setPackageInfo(packageConfig);

        autoGenerator.execute();

    }
}